package org.aiforum.backend.service;

import java.util.List;

import javax.transaction.Transactional;
import javax.transaction.Transactional.TxType;

import org.aiforum.backend.common.QueryPreperty;
import org.aiforum.backend.common.Response;
import org.aiforum.backend.mapper.TopicMapper;
import org.aiforum.domain.Topic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.util.StringUtil;
/**
 * 帖子业务实现类
 * @author Administrator
 *
 */
@Service("topicService")
@Transactional(TxType.REQUIRED)
public class TopicServiceImpl  implements TopicService{
    
	@Autowired
	private TopicMapper topicMapper;
	
	@Override
	public Topic find(int topicId) {
		Topic topic=topicMapper.findById(topicId);
		return topic;
	}

	@Override
	public Response delete(int topicId) {
		topicMapper.delete(topicId);
		Response response=Response.getInstaner();
		response.setState(true);
		response.setMessage("Delete Success");
		return response;
	}

	@Override
	public List<Topic> queryByPreperty(QueryPreperty queryPreperty) {
		
		if(StringUtil.isNotEmpty(queryPreperty.getQueryValue().toString())){
			String value="%"+queryPreperty.getQueryValue()+"%";
			queryPreperty.setQueryValue(value);
		}else{
			queryPreperty.setQueryValue(null);
		}
		return topicMapper.queryByPreperty(queryPreperty);
	}

}
